package com.example.hotHub.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R<T> {
    private Integer code;
    private String msg;
    private T data = null;

    public static Integer CODE_OK = 20000;
    public static Integer CODE_ERROR = 20001;

    public static String MSG_OK = "OK";
    public static String MSG_EEROR = "ERROR";

    private R() {}

    public static R success() {
        return new R().code(CODE_OK).msg(MSG_OK);
    }

    public static<T> R success(T data) {
        return new R().code(CODE_OK).msg(MSG_OK).data(data);
    }

    public static R error() {
        return new R().code(CODE_ERROR).msg(MSG_EEROR);
    }

    public R data(T data) {
        this.data = data;
        return this;
    }

    public R code(Integer code) {
        this.code = code;
        return this;
    }

    public R msg(String msg) {
        this.msg = msg;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "R{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
